Typical HAL CEC use cases for migration ¶
This section provides information about typical HAL CEC use cases for migration.
Use case: CEC transmit IT mode ¶
This use case describes how to transmit a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
CEC_HandleTypeDef hcec;
uint8_t Tab_Tx[2];
uint8_t DestinationAddress;
uint8_t InitiatorAddress;
uint32_t TxSize = 0X02;
hcec.Instance = CEC;
hcec.Init.OwnAddress = CEC_OWN_ADDRESS_1;
HAL_CEC_Init(&hcec);
InitiatorAddress = 0x1;
DestinationAddress = 0x3;
Tab_Tx[0] = 0x44;
Tab_Tx[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, InitiatorAddress, DestinationAddress, (uint8_t *)&Tab_Tx, TxSize);
|
hal_cec_handle_t hcec;
uint8_t tx_data_frame[2];
hal_cec_header_t tx_header;
hal_cec_header_t p_rx_header;
uint8_t rx_data_frame[2];
uint32_t max_size_byte = 0x02;
uint32_t tx_size = 0x02;
hal_cec_config_t config;
HAL_CEC_Init(&hcec, HAL_CEC);
config.own_address = HAL_CEC_OWN_ADDR_1;
HAL_CEC_SetConfig(&hcec, &config);
/* Start CEC in IT mode to enable the peripheral */
HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);
tx_header.initiator_address = 0x1;
tx_header.destination_address = 0x3;
tx_data_frame[0] = 0x44;
tx_data_frame[1] = 0x42;
HAL_CEC_Transmit_IT(&hcec, &tx_header, tx_data_frame, tx_size);
|
Key changes ¶
HAL2 separates initialization from configuration using
HAL_CEC_InitthenHAL_CEC_SetConfig.HAL2 requires starting the peripheral in IT mode using
HAL_CEC_Start_ITbefore transmitting.HAL2 uses typed configuration and header structures (for example
hal_cec_config_tandhal_cec_header_t) instead of passing raw addressing parameters.
Use case: CEC receive IT mode ¶
This use case describes how to receive a CEC frame in Interrupt mode (IT mode) using HAL1 and HAL2.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
CEC_HandleTypeDef hcec;
uint8_t Tab_Rx[3];
uint8_t New_RxBuffer[3];
hcec.Instance = CEC;
hcec.Init.OwnAddress = CEC_OWN_ADDRESS_3;
hcec.Init.SignalFreeTime = CEC_DEFAULT_SFT;
hcec.Init.Tolerance = CEC_STANDARD_TOLERANCE;
hcec.Init.BRERxStop = CEC_RX_STOP_ON_BRE;
hcec.Init.BREErrorBitGen = CEC_BRE_ERRORBIT_GENERATION;
hcec.Init.LBPEErrorBitGen = CEC_LBPE_ERRORBIT_GENERATION;
hcec.Init.BroadcastMsgNoErrorBitGen = CEC_BROADCASTERROR_ERRORBIT_GENERATION;
hcec.Init.SignalFreeTimeOption = CEC_SFT_START_ON_TXSOM;
hcec.Init.ListenMode = CEC_FULL_LISTENING_MODE;
hcec.Init.RxBuffer = Tab_Rx;
HAL_CEC_Init(hcec);
/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
HAL_CEC_ChangeRxBuffer(&hcec, New_RxBuffer);
}
|
hal_cec_handle_t hcec;
uint8_t rx_data_frame[2];
uint8_t new_rx_data_frame[2];
hal_cec_header_t p_rx_header;
uint32_t max_size_byte = 0x02;
hal_cec_config_t config;
HAL_CEC_Init(&hcec, HAL_CEC);
config.own_address = HAL_CEC_OWN_ADDR_5;
HAL_CEC_SetConfig(&hcec, &config);
/* Optional configurations */
HAL_CEC_SetSignalFreeTimeDuration(&hcec, HAL_CEC_SIG_FREETIME_DURATION_AUTO);
HAL_CEC_SetRxTolerance(&hcec, HAL_CEC_RX_TOLERANCE_STANDARD);
HAL_CEC_EnableRxStopUponBitRisingErr(&hcec);
HAL_CEC_EnableBitRisingErrGen(&hcec);
HAL_CEC_EnableLongBitPeriodErrGen(&hcec);
HAL_CEC_EnableBroadcastErrGen(&hcec);
HAL_CEC_SetSignalFreeTimeStart(&hcec, HAL_CEC_SIG_FREETIME_ON_MSG_START);
HAL_CEC_SetListenMode(&hcec, HAL_CEC_LISTEN_MODE_RECEIVE_ALL_MSG);
HAL_CEC_Start_IT(&hcec, &p_rx_header, rx_data_frame, max_size_byte);
/* After Rx complete */
HAL_CEC_RxCpltCallback(&hcec)
{
HAL_CEC_SetRxBuffer(&hcec, &p_rx_header, new_rx_data_frame, max_size_byte);
}
|
Key changes ¶
In HAL2, optional RX-related settings are configured through dedicated APIs (for example
HAL_CEC_SetRxTolerance) rather than through handle init fields.In HAL2, reception is started with
HAL_CEC_Start_ITand the RX buffer can be updated usingHAL_CEC_SetRxBuffer.HAL2 uses typed configuration structures (for example
hal_cec_config_tandhal_cec_header_t) and buffers passed as parameters.



![@startuml
' Fix order of each column
participant "User application" as user
participant "<b>HAL CEC driver</b>" as cec
participant "CEC IRQ handler" as isr
== CEC initialization ==
user -> cec : <color #Blue> HAL_CEC_Init</color>( hcec, HAL_CEC)
note right: <color #Blue> Initialize the CEC peripheral handle with a CEC instance.
cec --> user: HAL_OK
== CEC configuration ==
user -> cec : <color #Blue> HAL_CEC_SetConfig</color>( hcec, &p_config)
note right: <color #Blue> Set the CEC peripheral own address configuration.
cec --> user: HAL_OK
== CEC optional configuration ==
opt Optional signal free time duration
user -[#Blue]-> cec : HAL_CEC_SetSignalFreeTimeDuration( hcec, HAL_CEC_SIG_FREETIME_DURATION_AUTO )
note right: Set the signal free time duration to automatic management.
cec --> user : HAL_OK
end
opt Optional RX tolerance error behaviors
user -[#Blue]-> cec : HAL_CEC_SetRxTolerance( hcec, HAL_CEC_RX_TOLERANCE_STANDARD )
note right: Set the Rx tolerance to the STANDARD margin.\nUse HAL_CEC_RX_TOLERANCE_EXTENDED\nto reduce bit rising error occurrence.
cec --> user : HAL_OK
end
opt Optional RX stop behavior upon bit rising error
user -[#Blue]-> cec : HAL_CEC_EnableRxStopUponBitRisingErr( hcec )
note right: Enable Rx stop behavior upon a bit rising error occurrence.
cec --> user : HAL_OK
end
opt Optional generation of bit rising error
user -[#Blue]-> cec : HAL_CEC_EnableBitRisingErrGen( hcec )
note right: Enable bit rising error generation.
cec --> user : HAL_OK
end
opt Optional generation of broadcast message error
user -[#Blue]-> cec : HAL_CEC_EnableBroadcastErrGen( hcec )
note right: Enable broadcast message error generation.
cec --> user : HAL_OK
end
opt Optional signal free time start option
user -[#Blue]-> cec : HAL_CEC_SetSignalFreeTimeStart( hcec, HAL_CEC_SIG_FREETIME_ON_MSG_START )
note right: Enable signal free time start on message start of message.
cec --> user : HAL_OK
end
opt Optional listen mode
user -[#Blue]-> cec : HAL_CEC_SetListenMode( hcec, HAL_CEC_LISTEN_MODE_RECEIVE_ALL_MSG )
note right: Enable full listening mode to receive all messages.
cec --> user : HAL_OK
end
opt Optional generation of long bit period error
user -[#Blue]-> cec : HAL_CEC_EnableLongBitPeriodErrGen( hcec )
note right: Enable long bit period error generation.
cec --> user : HAL_OK
end
== CEC control ==
user -> cec : <color #Blue> HAL_CEC_Start_IT</color>( hcec, p_rx_header, rx_data_frame, max_size_byte )
note right: <color #Blue> Enable the CEC and set reception in IT mode: \n <font color=blue>- the IRQ handler processes the reception, byte per byte, and fills the data buffer.
cec --> user: HAL_OK
== CEC reception ==
isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <color #Blue> last byte reception
cec -> user : <font color=orange> HAL_CEC_RxCpltCallback() </font> user process for CEC Rx
note over user: <color #Blue> The user application has to: \n\
<color #Blue> copy the received data frame \n and can \n <color #Blue>swap the buffer pointer with HAL_CEC_SetRxBuffer( hcec, p_header, data_frame, max_size_byte )
group optional
user -> cec : <color #Blue> HAL_CEC_SetRxBuffer</color>( hcec, p_rx_header, rx_data_frame, max_size_byte)
note right: <color #Blue> Set a new buffer pointer using HAL_CEC_SetRxBuffer()\n <color #Blue>within HAL_CEC_RxCpltCallback()
cec --> user: HAL_OK
end
...
== CEC reception error handling ==
group If hardware error occurs :
isr -> cec : <font color=orange> HAL_CEC_IRQHandler()
note right: <font color=orange> interrupt when error
cec -> user : <font color=orange> HAL_CEC_ErrorCallback() </font> user process CEC line error
end
@enduml](../../../../../_images/plantuml-aa9d98c55b38ba7981138b523b0108a70b1471b8.png)